//2009/08/15 03:19:30
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

class ParameterSubstitution
{
public:
    string processParams(string code, vector <string> params)
    {
        string s;
        for (int i=0; i<code.size(); i++)
        {
            int dex = 0;
            int next = i;
            if (code[i] == '$')
            {
                if (i<code.size()-1 && code[i+1] != '0')
                {
                    for (int j=i+1; j<code.size(); j++)
                    {
                        if (!isdigit(code[j])) break;
                        int t = dex * 10 + code[j] - '0';
                        if (t >0 && t<=params.size())
                        {
                            dex = t;
                            next = j;
                        }
                    }
                }
            }
            if (dex > 0)
            {
                i = next;
                s += params[dex - 1];
            }
            else s += code[i];
        }
        return s;
    }
};
